﻿// ----------------------------------------------------------------------
// <copyright file="ListContext.cs" company="Meligo">
//     Copyright statement. All right reserved
// </copyright>
//
// ------------------------------------------------------------------------

namespace Meligo.ModuleExtractor.GenerateModuleFactory.Entities
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class ListContext
    {
        /// <summary>
        /// list context
        /// </summary>
        /// <param name="list"></param>
        public ListContext(SPList list)
        {
            this.FieldMap = list.Fields.Cast<SPField>().ToDictionary((SPField f) => f.Id);
            this.FieldNameMap = list.Fields.Cast<SPField>().ToDictionary((SPField f) => f.InternalName);
            this.ContentTypeMap = list.ContentTypes.Cast<SPContentType>().ToDictionary((SPContentType ct) => ct.Name, (SPContentType ct) => new HashSet<Guid>(from SPField f in ct.Fields select f.Id), StringComparer.OrdinalIgnoreCase);
        }

       /// <summary>
       /// FieldNameMap property
       /// </summary>
        public Dictionary<string, SPField> FieldNameMap
        {
            get;
            set;
        }

        /// <summary>
        /// FieldMap property
        /// </summary>
        public Dictionary<Guid, SPField> FieldMap 
        { 
            get; 
            set; 
        }

        /// <summary>
        /// Content type map property
        /// </summary>
        public Dictionary<string, HashSet<Guid>> ContentTypeMap 
        {
            get;
            set; 
        }
    }
}
